#include "MainHeader.h"
sCombo cTransparency;
sCombo cMusic;
sCombo cEffect;
sCombo cMiniX;
sCombo cMiniY;
sCombo cmTileset;
sCombo cSpriteset;
sCombo cSYP;
sCombo cTrans;
sCombo cF;
sCombo cL;
sCombo cB;
sCombo cBI;
sCombo cEC;
sCombo cSG;
sCombo cControl1;
sCombo cControl2;
sCombo cControl3;
sCombo cControl4;
BOOL CALLBACK  HeaderProced(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
	RHeader* RoomHeader=GameEngine->Members.RoomHeader;
	u8 Width=0;
	u8 Height=0;
    int i =0;
	switch (message) 
	{
	case WM_INITDIALOG:
		hwndHeader = hWnd;
		SetupHeaderControls();
		break;
		
		
	case WM_LBUTTONDOWN:
		
		
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam)){
		
        case WM_DESTROY:
		  ShowWindow(hWnd,SW_HIDE);
		break;	
		case cboSprites:
			LoadHeaderControls();
			break;
		case cmdChangeS:
            ChangeSprites();
			LoadHeaderControls();
			break;
		case cboSG:
				if(HIWORD(wParam)==CBN_SELCHANGE){
					switch(cSpriteset.GetListIndex()){
					case 0:
						RoomHeader->bSpriteIndex1=(u8)cSG.GetListIndex();
						break;
					case 1:
            			RoomHeader->bSpriteIndex2=(u8)cSG.GetListIndex();
					break;
					case 2:
						RoomHeader->bSpriteIndex3=(u8)cSG.GetListIndex();
					break;




					}
				}
			break;
		case cboEC:
			if(HIWORD(wParam)==CBN_SELCHANGE){{
				switch(cSpriteset.GetListIndex()){

				case 0:
		    		RoomHeader->bEventSwitch=(u8)cEC.GetListIndex();
					break;
				case 1:
            		RoomHeader->bEventSwitch2=(u8)cEC.GetListIndex();
				break;
			


				}
			}
			break;
			case cboTileset:
					if(HIWORD(wParam)==CBN_SELCHANGE){
						RoomHeader->bTileset = cmTileset.GetListIndex();
						 GetTileset(cmTileset.GetListIndex());
						 ThisForeground->Dirty = ThisLevelData->Dirty = ThisBackLayer->Dirty=1;
						 DrawRoom();
					}
				break;
			case cboTrans:
				if(HIWORD(wParam)==CBN_SELCHANGE){
					RoomHeader->TransForeground=cTransparency.GetListIndex();
					ThisForeground->Dirty =1;
					DrawRoom();

				}
				break;
			case cboSYP:
				if(HIWORD(wParam)==CBN_SELCHANGE){

                 RoomHeader->bSceneryYPos=cSYP.GetListIndex();
                 DrawRoom();

				}
				break;
				
			case cboMusic:
				if(HIWORD(wParam)==CBN_SELCHANGE){

                 RoomHeader->bMusic=cMusic.GetListIndex();
                

				}
				break;	
			case cboEffect:
				if(HIWORD(wParam)==CBN_SELCHANGE){

                 RoomHeader->bEffect=cEffect.GetListIndex();
                

				}
				break;	
		}
		break;
	
		case WM_SHOWWINDOW:
			SendMessage(hwndMM,WM_COMMAND,LOWORD(cboMAreaC),0);
			break;
		}	
			
	}
	
	//	return DefWindowProc(hWnd, message, wParam, lParam);
	return 0;
}
int SetupHeaderControls(){
	char buffer[256]={0};
int i=0;
char Compress[3][5]={"None","RLE","LZ77"};
  cTransparency.Init(GetDlgItem(hwndHeader,cboTrans));
 cMusic.Init(GetDlgItem(hwndHeader,cboMusic));
 cEffect.Init(GetDlgItem(hwndHeader,cboEffect));
 cMiniX.Init(GetDlgItem(hwndHeader,cboMiniX));
 cMiniY.Init(GetDlgItem(hwndHeader,cboMiniY));
 cmTileset.Init(GetDlgItem(hwndHeader,cboTileset));
 cSpriteset.Init(GetDlgItem(hwndHeader,cboSprites));
 cSYP.Init(GetDlgItem(hwndHeader,cboSYP));
 //cTrans.Init(GetDlgItem(hwndHeader,cboTrans));
 cEC.Init(GetDlgItem(hwndHeader,cboEC));
 cSG.Init(GetDlgItem(hwndHeader,cboSG));
 cF.Init(GetDlgItem(hwndHeader,cboCF));
 cL.Init(GetDlgItem(hwndHeader,cboCL));
 cB.Init(GetDlgItem(hwndHeader,cboCB));
 cBI.Init(GetDlgItem(hwndHeader,cboCBI));
 cControl1.Init(GetDlgItem(hwndHeader,cboControl1));
 cControl2.Init(GetDlgItem(hwndHeader,cboControl2));
 cControl3.Init(GetDlgItem(hwndHeader,cboControl3));
 cControl4.Init(GetDlgItem(hwndHeader,cboControl4));
	for(i = 0;i<256;i++){
     sprintf(buffer,"%X",i);
     cTransparency.Additem(buffer);
	 cMusic.Additem(buffer);
	 cEffect.Additem(buffer);
	 cMiniX.Additem(buffer);
	 cMiniY.Additem(buffer);
	 cmTileset.Additem(buffer);
	 if(i<3)cSpriteset.Additem(buffer);
	 cSYP.Additem(buffer);
	 cTrans.Additem(buffer);
	 cEC.Additem(buffer);
	 cSG.Additem(buffer);
		 if(16>i){
			 cControl1.Additem(buffer);
			 cControl2.Additem(buffer);
			 cControl3.Additem(buffer);
			 cControl4.Additem(buffer);
		 }
	}
    for(i=0;i<3;i++){
		cF.Additem(Compress[i]);
	    cL.Additem(Compress[i]);
        cB.Additem(Compress[i]);
        cBI.Additem(Compress[i]);
	}
	cSpriteset.SetListIndex(0);
	return 0;
}

int LoadHeaderControls(){
   char itembuf[256];
	//Load layer stuff first
    //Foreground
   RHeader* RoomHeader=GameEngine->Members.RoomHeader;
   u32 Offset;

       Offset=((RoomOffsets[Combos[cArea].GetListIndex()] - 0x8000000) + Combos[cRoom].GetListIndex() * 0x3C);

 sprintf(itembuf, "For manual editing this header can be found at offset: %6X",Offset);
 SetWindowText(GetDlgItem(hwndHeader,lblHeaderOffset), itembuf);
 if(RoomHeader->bBg0 &  0x40){
 	cF.SetListIndex(2);
	}else if(RoomHeader->bBg0 & 0x10){
	 cF.SetListIndex(1);
	}else{
	 cF.SetListIndex(0);
	}

 if(RoomHeader->bBg1 &  0x40){
 	cL.SetListIndex(2);
	}else if(RoomHeader->bBg1 & 0x10){
	 cL.SetListIndex(1);
	}else{
	 cL.SetListIndex(0);
	}

 if(RoomHeader->bBg2 &  0x40){
 	cB.SetListIndex(2);
	}else if(RoomHeader->bBg2 & 0x10){
	 cB.SetListIndex(1);
	}else{
	 cB.SetListIndex(0);
	}
 if(RoomHeader->lBg3 &  0x40){
 	cBI.SetListIndex(2);
	}else if(RoomHeader->lBg3 & 0x10){
	 cBI.SetListIndex(1);
	}else{
	 cBI.SetListIndex(0);
	}



   //Load offsets
   sprintf(itembuf,"%X",RoomHeader->lForeground-0x8000000);
   SetWindowText(GetDlgItem(hwndHeader,txtFO),itembuf);
   sprintf(itembuf,"%X",RoomHeader->lLevelData-0x8000000);
   SetWindowText(GetDlgItem(hwndHeader,txtLO),itembuf);
   sprintf(itembuf,"%X",RoomHeader->lBackLayer-0x8000000);
   SetWindowText(GetDlgItem(hwndHeader,txtBO),itembuf);
   sprintf(itembuf,"%X",RoomHeader->lBackgroundTSA-0x8000000);
   SetWindowText(GetDlgItem(hwndHeader,txtBIO),itembuf);
   cSYP.SetListIndex(RoomHeader->bSceneryYPos);
   cTransparency.SetListIndex(RoomHeader->TransForeground);
   cMusic.SetListIndex(RoomHeader->bMusic);
   cEffect.SetListIndex(RoomHeader->bEffect);
   cmTileset.SetListIndex(RoomHeader->bTileset);
   cMiniX.SetListIndex(RoomHeader->bMiniMapRoomX);
   cMiniY.SetListIndex(RoomHeader->bMiniMapRoomY);

   switch(cSpriteset.GetListIndex()){
	   EnableWindow(cEC.thishwnd(),1);
	case 0:
     cEC.SetListIndex(RoomHeader->bEventSwitch);
	 sprintf(itembuf,"Spriteset %X has %X number of sprites",cSpriteset.GetListIndex(),Enemy1.max);
	 SetWindowText(GetDlgItem(hwndHeader,lblNumber),itembuf);
     cSG.SetListIndex(RoomHeader->bSpriteIndex1);
	sprintf(itembuf,"%X",RoomHeader->lSpritePointer);
    SetWindowText(GetDlgItem(hwndHeader,txtSOffset),itembuf);
    break;
	case 1:

     cEC.SetListIndex(RoomHeader->bEventSwitch2);
     cSG.SetListIndex(RoomHeader->bSpriteIndex2);
	sprintf(itembuf,"%X",RoomHeader->lSpritePointer2);
    SetWindowText(GetDlgItem(hwndHeader,txtSOffset),itembuf);
 sprintf(itembuf,"Spriteset %X has %X number of sprites",cSpriteset.GetListIndex(),Enemy2.max);
	 SetWindowText(GetDlgItem(hwndHeader,lblNumber),itembuf);
    break;
	case 2:
	EnableWindow(cEC.thishwnd(),0);
    
     cSG.SetListIndex(RoomHeader->bSpriteIndex3);
	sprintf(itembuf,"%X",RoomHeader->lSpritePointer3);
    SetWindowText(GetDlgItem(hwndHeader,txtSOffset),itembuf);
	 sprintf(itembuf,"Spriteset %X has %X number of sprites",cSpriteset.GetListIndex(),Enemy3.max);
	 SetWindowText(GetDlgItem(hwndHeader,lblNumber),itembuf);
    break;
   }
    cControl1.SetListIndex(RoomHeader->bBg0 & 0xF);
	cControl2.SetListIndex(RoomHeader->bBg1 & 0xF);
	cControl3.SetListIndex(RoomHeader->bBg2 & 0xF);
	cControl4.SetListIndex(RoomHeader->lBg3 & 0xF);
	return 0;
}

int ChangeSprites(){
	RHeader* RoomHeader=GameEngine->Members.RoomHeader;
	int i= 0;
	int set= cSpriteset.GetListIndex();
	char blah[1024]="Please enter a new number\nfor the amount of sprites you want.\nMax is 255, least is 0 in hex ";
    int sprites=0;
	
    u32* offsets[3]={&RoomHeader->lSpritePointer,&RoomHeader->lSpritePointer2,&RoomHeader->lSpritePointer3};
	nEnemyList* cursz[3] = {&Enemy1, &Enemy2, &Enemy3};
	

	memcpy(procstring,blah, 1024);
   	sprites = LoadInput(cursz[set]->max);
       //We now have how many 
    if(sprites < 0) sprites = 0; 
	if(sprites > 32)sprites = 32;//Is this even possible? XD ask PJ
	//Then see if sprites is bigger then current sets max

	if(sprites>(cursz[set]->max))//Bigger let's find some space
		*offsets[set] = GBA.FindFreeSpace(sprites*3+32,0xFF) + 0x8000000;//Find more than enough free bytes
	
	fseek(GBA.ROM, *offsets[set] - 0x8000000, SEEK_SET);
	for(i = 0; i<cursz[set]->max;i++)
         fwrite(&cursz[set]->Enemies[i],3,1,GBA.ROM);
    cursz[set]->max=sprites;
		
		//Put 3 bytes to say we're done
		fputc(0xFF,GBA.ROM);
		fputc(0xFF,GBA.ROM);
		fputc(0xFF,GBA.ROM);
	SaveHeader(1);
	DrawRoom();
	//	LoadEnemies();

	return 0;
}

int SaveHeader(u8 call){
	RHeader* RoomHeader=GameEngine->Members.RoomHeader;
   u32  ho=0;//ho is Header offset :D
   char itembuf[256]={0};
	//Load layer stuff first
    //Foreground


   //Load offsets
   if(call!=2){
  RoomHeader->lForeground=0;
  RoomHeader->lLevelData=0;
  RoomHeader->lBackLayer=0;
  RoomHeader->lBackgroundTSA=0;
   GetWindowText(GetDlgItem(hwndHeader,txtFO),itembuf,256);
   sscanf(itembuf,"%X",&RoomHeader->lForeground);
   RoomHeader->lForeground+=0x8000000;
   GetWindowText(GetDlgItem(hwndHeader,txtLO),itembuf,256);
   sscanf(itembuf,"%X",&RoomHeader->lLevelData);
   RoomHeader->lLevelData+=0x8000000;
   GetWindowText(GetDlgItem(hwndHeader,txtBO),itembuf,256);
   sscanf(itembuf,"%X",&RoomHeader->lBackLayer);
   RoomHeader->lBackLayer+=0x8000000;
   GetWindowText(GetDlgItem(hwndHeader,txtBIO),itembuf,256);
   sscanf(itembuf,"%X",&RoomHeader->lBackgroundTSA);
   RoomHeader->lBackgroundTSA+=0x8000000;
   RoomHeader->bSceneryYPos=(u8)cSYP.GetListIndex();
   RoomHeader->TransForeground=(u8)cTransparency.GetListIndex();
   RoomHeader->bMusic=(u8)cMusic.GetListIndex();
   RoomHeader->bEffect=(u8)cEffect.GetListIndex();
   RoomHeader->bTileset=(u8)cmTileset.GetListIndex();
   RoomHeader->bMiniMapRoomX=(u8)cMiniX.GetListIndex();
   RoomHeader->bMiniMapRoomY=(u8)cMiniY.GetListIndex();

   switch(cSpriteset.GetListIndex()){
	   EnableWindow(cEC.thishwnd(),1);
	case 0:
     cEC.SetListIndex(RoomHeader->bEventSwitch);
	 sprintf(itembuf,"Spriteset %X has %X number of sprites",cSpriteset.GetListIndex(),Enemy1.max);
	 SetWindowText(GetDlgItem(hwndHeader,lblNumber),itembuf);
     cSG.SetListIndex(RoomHeader->bSpriteIndex1);
	sprintf(itembuf,"%X",RoomHeader->lSpritePointer);
    SetWindowText(GetDlgItem(hwndHeader,txtSOffset),itembuf);
    break;
	case 1:

     cEC.SetListIndex(RoomHeader->bEventSwitch2);
     cSG.SetListIndex(RoomHeader->bSpriteIndex2);
	sprintf(itembuf,"%X",RoomHeader->lSpritePointer2);
    SetWindowText(GetDlgItem(hwndHeader,txtSOffset),itembuf);
 sprintf(itembuf,"Spriteset %X has %X number of sprites",cSpriteset.GetListIndex(),Enemy2.max);
	 SetWindowText(GetDlgItem(hwndHeader,lblNumber),itembuf);
    break;
	case 2:
	EnableWindow(cEC.thishwnd(),0);
    
     cSG.SetListIndex(RoomHeader->bSpriteIndex3);
	sprintf(itembuf,"%X",RoomHeader->lSpritePointer3);
    SetWindowText(GetDlgItem(hwndHeader,txtSOffset),itembuf);
	 sprintf(itembuf,"Spriteset %X has %X number of sprites",cSpriteset.GetListIndex(),Enemy3.max);
	 SetWindowText(GetDlgItem(hwndHeader,lblNumber),itembuf);
    break;
   }
   	switch(	cF.GetListIndex()){
		case 0:
          RoomHeader->bBg0=(u8)cControl1.GetListIndex();

		break;
        case 1:
          RoomHeader->bBg0=0x10+((u8)cControl1.GetListIndex());
		break;
		 case 2:
          RoomHeader->bBg0=0x40+((u8)cControl1.GetListIndex());
		break;

	}
		switch(	cL.GetListIndex()){
		case 0:
          RoomHeader->bBg1=((u8)cControl2.GetListIndex());

		break;
        case 1:
          RoomHeader->bBg1=0x10+((u8)cControl2.GetListIndex());
		break;
		 case 2:
          RoomHeader->bBg1=0x40+((u8)cControl2.GetListIndex());
		break;

	}
	switch(	cB.GetListIndex()){
		case 0:
          RoomHeader->bBg2=((u8)cControl3.GetListIndex());

		break;
        case 1:
          RoomHeader->bBg2=0x10+((u8)cControl3.GetListIndex());
		break;
		 case 2:
          RoomHeader->bBg2=0x40+((u8)cControl3.GetListIndex());
		break;

	}if(!import){
		switch(	cBI.GetListIndex()){
		
			case 0:
				 RoomHeader->lBg3=((u8)cControl4.GetListIndex());

				break;
			case 1:
				  RoomHeader->lBg3=0x10+((u8)cControl4.GetListIndex());
				break;
			case 2:
				  RoomHeader->lBg3=0x40+((u8)cControl4.GetListIndex());
				break;
		}
		} else {
          RoomHeader->lBg3=0xF0+((u8)cControl4.GetListIndex());;
		  import = 0;
		}

}
   	if(GameEngine->isZM()){
		ho=((RoomOffsets[Combos[cArea].GetListIndex()]-0x8000000) + Combos[cRoom].GetListIndex()*0x3C);
	}else if (GameEngine->isMF()){
		ho=((RoomOffsets[Combos[cArea].GetListIndex()]-0x8000000) + Combos[cRoom].GetListIndex()*0x3C);
	}
	fseek(GBA.ROM,ho,SEEK_SET);
	fwrite(&RoomHeader->bTileset,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bBg0,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bBg1,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bBg2,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->lBg3,sizeof(u32),1,GBA.ROM);
	fwrite(&RoomHeader->lForeground,sizeof(u32),1,GBA.ROM); 
	fwrite(&RoomHeader->lLevelData,sizeof(u32),1,GBA.ROM);
    fwrite(&RoomHeader->lBackLayer,sizeof(u32),1,GBA.ROM);
    fwrite(&RoomHeader->lClipData,sizeof(u32),1,GBA.ROM); 
	fwrite(&RoomHeader->lBackgroundTSA,sizeof(u32),1,GBA.ROM);
	fwrite(&RoomHeader->bUnknown1,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->TransForeground,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->iSep1,sizeof(u16),1,GBA.ROM);
	fwrite(&RoomHeader->lSpritePointer,sizeof(u32),1,GBA.ROM); 
	fwrite(&RoomHeader->bSpriteIndex1,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bEventSwitch,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->iSep2,sizeof(u16),1,GBA.ROM);
	fwrite(&RoomHeader->lSpritePointer2,sizeof(u32),1,GBA.ROM); 
	fwrite(&RoomHeader->bSpriteIndex2,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bEventSwitch2,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->iSeperator,sizeof(u16),1,GBA.ROM);
	fwrite(&RoomHeader->lSpritePointer3,sizeof(u32),1,GBA.ROM); 
	fwrite(&RoomHeader->bSpriteIndex3,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bMiniMapRoomX,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bMiniMapRoomY,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bEffect,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bSceneryYPos,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bNothing,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->bMusic,sizeof(u8),1,GBA.ROM);
	fwrite(&RoomHeader->blank,sizeof(u8),1,GBA.ROM);


	if(call==0)SendMessage(Main,WM_COMMAND,cboRoom,0);
	return 0;
}

int CCForeground(){
	RHeader* RoomHeader=GameEngine->Members.RoomHeader;
	int blah=SceneType;
	long someaddress=0;
	u8   compressdata[32192]={0};
	switch(	cF.GetListIndex()){
		// ChangeCompression(RoomHeader->bBg0, 0, 0, &ThisBackground);
         RoomHeader->bBg0=0;
		 break;
	 case 1:
	//	 ChangeCompression(RoomHeader->bBg1, 1, 0, &ThisBackground);
		 RoomHeader->bBg0=0x10;
//	     SaveBackground();
		 break;

	 case 2:
	//		ChangeCompression(RoomHeader->bBg1, 2, 0, &ThisBackground);
			RoomHeader->bBg0=0x40;
		 break;
	}

	return 0;
}
int CCLevel(){
	RHeader* RoomHeader=GameEngine->Members.RoomHeader;
	switch(	cL.GetListIndex()){
	 	 ChangeCompression(RoomHeader->bBg1, 0, 1, ThisBackground);
         RoomHeader->bBg1=0;
		 break;
	 case 1:
		 ChangeCompression(RoomHeader->bBg1, 1, 1, ThisBackground);
		 RoomHeader->bBg1=0x10;
//	     SaveBackground();
		 break;

	 case 2:
		ChangeCompression(RoomHeader->bBg1, 2, 1, ThisBackground);
			RoomHeader->bBg1=0x40;
		 break;
	}

	return 0;
}

int CCBacklayer(){
	RHeader* RoomHeader=GameEngine->Members.RoomHeader;
	switch(	cB.GetListIndex()){
      case 0:
		 ChangeCompression(RoomHeader->bBg2, 0, 2, ThisBackground);
         RoomHeader->bBg2=0;
		 break;
	 case 1:
	     ChangeCompression(RoomHeader->bBg2, 1, 2, ThisBackground);
		 RoomHeader->bBg2=0x10;
     //SaveBackground();
		 break;

	 case 2:
		ChangeCompression(RoomHeader->bBg2, 2, 2, ThisBackground);
			RoomHeader->bBg2=0x40;
		 break;
	}

	return 0;
}
int CCBackground(){
	
RHeader* RoomHeader=GameEngine->Members.RoomHeader;
	
	
	switch(	cBI.GetListIndex()){
	 case 0:
		 ChangeCompression((u8)RoomHeader->lBg3, 0, 3, ThisBackground);
         RoomHeader->lBg3=0;
		 break;
	 case 1:
		 ChangeCompression((u8)RoomHeader->lBg3, 1, 3, ThisBackground);
		 RoomHeader->lBg3=0x10;
//	     SaveBackground();
		 break;

	 case 2:
			ChangeCompression((u8)RoomHeader->lBg3, 2, 3, ThisBackground);
			RoomHeader->lBg3=0x40;
		 break;
	}

	return 0;
}
void setsize(nRoomBuff* buffer){


		  u32 fgW= (buffer->X+16)/32, fgH= (buffer->Y+16)/32;

			if(fgW > 2)	fgW= 2;
			if(fgH > 2)	fgH= 2;

			if( fgW==1 && fgH==1 )	buffer->size=0;
			else if( fgW==1 && fgH==2)	buffer->size=2;
			else buffer->size= 1;

}

void ChangeCompression(u8 oldlayervalue, u8 newval, u8 layer, nRoomBuff* buffer){


	u8 oldscene; 

	switch(	newval){
	 case 0:
         oldlayervalue=0;
		 break;
	 case 1:
		 if(oldlayervalue==0){
			 buffer->X=ThisClipData->X;//Because clipdata will never be 0!
			 buffer->Y=ThisClipData->Y;
			 memset((u8*)buffer->TileBuf2D,0,0xFE00);
		 }
		

		 break;

	 case 2:
		 oldscene = SceneType;
		  if(layer == 1) {
          MessageBox(0,"Level Data can not be LZ compressd\nSwitching to RLE compression","Error",MB_OK);
          SceneType=oldscene;
		  ChangeCompression(oldlayervalue, 1, layer,buffer);

		 }
		 if(oldlayervalue==0x10){
	     	setsize(buffer);
		 } else if(oldlayervalue==0){
		  buffer->X=32;
		  buffer->Y=32;
		  memset((u8*)buffer->TileBuf2D,0,0xFE00);
		 }
		 switch(layer){
		 case 0:
           SceneType=2;
         break;
		 case 2:
			 SceneType = 1;
         break;
		 case 3:
			 SceneType = 0;
		 break;
		 }

		 
		// SaveCurScene();
	      SceneType=oldscene;
		 break;
	}



}


int BackUpAllHeaders(){
	char curpath[2048]={0};
	int ai=0;//Area Index;
	int ri=0;//Room Index
	int lc=0;
	FILE* fp=NULL;
	u8  roomarray[0x3c];
RHeader* RoomHeader=GameEngine->Members.RoomHeader;
	
    memcpy(curpath,AppPath,strlen(AppPath));
	if(GameEngine->isZM()){
		for(ai=0;ai<7;ri++){
			if(ai== 6) {
				lc = 0x63;
				}else{
				lc = (RoomOffsets[ai+ 1] - RoomOffsets[ai]) / 0x3C;
			}
             fseek(GBA.ROM,RoomOffsets[ai]-0x8000000,SEEK_SET);
				for(ri = 0;ri<lc;ri++){
					memset(curpath,0,2048);
					fread(roomarray,0x3c,1,GBA.ROM);
                    strcat(curpath,AppPath);
					strcat(curpath,"\\ZM\\HdrBackUp\\");
//                    strcat(curpath,Combos[cboArea].sList(ai));
				}


		}
	}else 	if(GameEngine->isMF()){
    }

return 0;
}

int InsertAllHeaders(){


return 0;
}
int BackUpAreaHeaders(){
	return 0;
}
int InsertAreaHeaders(){


	return 0;
}
int BackupCurHeader(){

	return 0;
}

int InsertCurHeader(){

	return 0;
}

int BackupAheaderInThisArea(){

	return 0;
}
int BackupAHeader(){

	return 0;
}
int InsertAHeaderInThisArea(){

	return 0;
}

int InsertAHeader(){

	return 0;
}